﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using DevExpress.Web.Mvc;
using EnterpriseFund.Common;
using Newtonsoft.Json;
using DevExpress.Web.ASPxGridView;
using System.Web.UI;
using EnterpriseFund.BLL;
using DevExpress.Utils;
using DevExpress.XtraReports.UI;
using DevExpress.XtraPrinting;

namespace EnterpriseFund.Controllers
{
  
    public class QueryYearSummarySheetController : Controller
    {
        //
        // GET: /QueryYearSummarySheet/

        public ActionResult Index()
        {
            string year = (decimal.Parse(OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR))).ToString();
            EnterpriseFund.BLL.QueryYearSummarySheet qbll = new BLL.QueryYearSummarySheet();
            var zsxx = qbll.GetModelList("FYear = '" + year + "'");
            EnterpriseFund.BLL.SpecialAdjustCls sbll = new EnterpriseFund.BLL.SpecialAdjustCls();
            var vf = sbll.GetModelList1("");
            //var vfa= from p in vf.Tables[0].t 
            //         group p  by new { p.}
            ViewData["year"] = year;
                    
            ViewData["FinancePropList"] = vf;
            DataTable dt = modeltotable(zsxx);
           // return View("Index", dt);
            return View();
        }

        public string GetFetchString()
        {
             var NSRMC = Fetch.Post("hNSRMC");
            var FFinance = Fetch.Post("hFFinance");
            var NSRBM = Fetch.Post("hNSRBM");
            var NSRSBH = Fetch.Post("hNSRSBH");
            // var FNewEnterprise = Fetch.Post("hFNewEnterprise");
              var FIssueID = Fetch.Post("hFIssueID");
            //  var ISPAY = Fetch.Post("hISPAY");
            var FYear = Fetch.Post("hFYear");
            ViewData["NSRMC"] = NSRMC;
            ViewData["FFinance"] = FFinance;
            ViewData["NSRBM"] = NSRBM;
            ViewData["NSRSBH"] = NSRSBH;
            //ViewBag.FNewEnterprise = FNewEnterprise;
            ViewData["FIssueID"] = FIssueID;
            //ViewBag.ISPAY = ISPAY;
            ViewData["FYear"] = FYear;
            return "";
        }
        public ActionResult Print()
        {
            GetFetchString();
            // CreatReport(table);
            return View("Print");
        }
        private static DataTable modeltotable(List<Model.QueryYearSummarySheet> zsxx)
        {
            var vsbzsxx2 = from p in zsxx where !string.IsNullOrEmpty(p.FNote)
                           group p by new { p.NSRDZDAH, p.NSRBM, p.NSRMC, p.NSRSBH, p.FYear } into g
                           select new
                           {
                               NSRDZDAH = g.Key.NSRDZDAH,

                               NSRBM = g.Key.NSRBM,
                               NSRMC = g.Key.NSRMC,
                               NSRSBH = g.Key.NSRSBH,
                               FNotes = string.Join("\r\n", g.Where(y=>!string.IsNullOrEmpty(y.FNote)).Select(h => h.FNote)),
                               //  FApplyDate = g.Min(sg => DateTime.Parse(sg.FApplyDate.ToString())).ToString("yyyy-MM-dd"),
                               FYear = g.Key.FYear.ToString()
                           };
            DataTable dt = new DataTable();
            if (dt.Columns.Count==0)
            {
                dt.Columns.Add("NSRDZDAH");
                dt.Columns.Add("NSRBM");
                dt.Columns.Add("NSRMC");
                dt.Columns.Add("NSRSBH");
                dt.Columns.Add("FNotes");
                dt.Columns.Add("FYear");
                dt.Columns.Add("rownum");

            }
            int i = 0;
            foreach (var v in vsbzsxx2)
            {
                i++;
                DataRow r = dt.NewRow();
                r["NSRDZDAH"] = v.NSRDZDAH;
                r["NSRBM"] = v.NSRBM;
                r["NSRMC"] = v.NSRMC;
                r["NSRSBH"] = v.NSRSBH;
                r["FNotes"] = v.FNotes;
                r["FYear"] = v.FYear;
                r["rownum"] = i;
                dt.Rows.Add(r);
            }
            return dt;
        }
        private static DataTable modeltotableext(List<Model.QueryYearSummarySheet> zsxx)
        {
            var vsbzsxx2 = from p in zsxx
                           where !string.IsNullOrEmpty(p.FNote)
                           group p by new { p.NSRDZDAH, p.NSRBM, p.NSRMC, p.NSRSBH, p.FYear } into g
                           select new
                           {
                               NSRDZDAH = g.Key.NSRDZDAH,

                               NSRBM = g.Key.NSRBM,
                               NSRMC = g.Key.NSRMC,
                               NSRSBH = g.Key.NSRSBH,
                               FNotes = string.Join("\r\n", g.Where(y => !string.IsNullOrEmpty(y.FNote)).Select(h => h.FNote)),
                               //  FApplyDate = g.Min(sg => DateTime.Parse(sg.FApplyDate.ToString())).ToString("yyyy-MM-dd"),
                               FYear = g.Key.FYear.ToString()
                           };
            DataTable dt = new DataTable();
            if (dt.Columns.Count == 0)
            {
                dt.Columns.Add("NSRDZDAH");
                dt.Columns.Add("NSRBM");
                dt.Columns.Add("NSRMC");
                dt.Columns.Add("NSRSBH");
                dt.Columns.Add("FNotes");
                dt.Columns.Add("FYear");
                dt.Columns.Add("rownum");

            }
            int i = 0;
            foreach (var v in vsbzsxx2)
            {
                i++;
                DataRow r = dt.NewRow();
                r["NSRDZDAH"] = v.NSRDZDAH;
                r["NSRBM"] = v.NSRBM;
                r["NSRMC"] = v.NSRMC;
                r["NSRSBH"] = v.NSRSBH;
                r["FNotes"] = v.FNotes;
                r["FYear"] = v.FYear;
                r["rownum"] = i;
                dt.Rows.Add(r);
            }
            return dt;
        }
        public ActionResult QueryYearSummarySheetListPartial()
        {
            GetWhereString();
            var vsbzsxx = GetModelVSBZSXX();
            var vsbzsxx2 = modeltotable(vsbzsxx);
            //var vsbzsxx2 = from p in vsbzsxx
            //               group p by new { p.NSRDZDAH, p.NSRBM, p.NSRMC, p.NSRSBH, p.FYear } into g
            //               select new
            //               {
            //                   NSRDZDAH = g.Key.NSRDZDAH,

            //                   NSRBM = g.Key.NSRBM,
            //                   NSRMC = g.Key.NSRMC,
            //                   NSRSBH = g.Key.NSRSBH,
            //                   FAuditAmount = g.Sum(gs => gs.FAuditAmount) / 10000,
            //                   FApplyDate = g.Min(sg => DateTime.Parse(sg.FApplyDate.ToString())).ToString("yyyy-MM-dd"),
            //                   FYear = g.Key.FYear.ToString()
            //               };
            //var vsbzsxx2 = from p in vsbzsxx
            //               group p by new { p.NSRDZDAH, p.NSRBM, p.NSRMC, p.NSRSBH, p.FYear } into g
            //               select new
            //               {
            //                   NSRDZDAH = g.Key.NSRDZDAH,

            //                   NSRBM = g.Key.NSRBM,
            //                   NSRMC = g.Key.NSRMC,
            //                   NSRSBH = g.Key.NSRSBH,
            //                   FNotes = string.Join(",", g.Select(h => h.FNote)),
            //                   //  FApplyDate = g.Min(sg => DateTime.Parse(sg.FApplyDate.ToString())).ToString("yyyy-MM-dd"),
            //                   FYear = g.Key.FYear.ToString()
            //               };
            //foreach (var x in vsbzsxx2)
            //{
            //    x.FAuditAmount = decimal.Parse(x.FAuditAmount.ToString()) / 10000;
            //}
            return View(vsbzsxx2);
        }
        public ActionResult ReportViewerPartial()
        {
            var strWhere = GetWhereString();
            EnterpriseFund.BLL.QueryYearSummarySheet qbll = new BLL.QueryYearSummarySheet();
            var zsxx =modeltotableext( qbll.GetModelList(strWhere));
            MVCReportGeneratonHelper generator = new MVCReportGeneratonHelper();
            generator.CustomizeColumnsCollection += new CustomizeColumnsCollectionEventHandler(generator_CustomizeColumnsCollection);
            generator.CustomizeColumn += new CustomizeColumnEventHandler(generator_CustomizeColumn);
            XtraReport report = generator.GenerateMVCReport(OperateSession.GetFromCache("QueryYearSummarySheet") as MVCxGridViewState, zsxx);
            //  XtraReport report = generator.GenerateMVCReport(gridViewState, dt);

            //report.PaperKind = System.Drawing.Printing.PaperKind.A4;

            this.ViewData["rpt"] = report;

            return PartialView("ReportViewerPartial");

        }

        void generator_CustomizeColumnsCollection(object source, ColumnsCreationEventArgs e)
        {
            for (int i = 0; i < e.ColumnsInfo.Count; i++)
            {

                if (e.ColumnsInfo[i].FieldName == "rownum")
                {
                    e.ColumnsInfo[i].ColumnWidth =50 ;
                }
                if (e.ColumnsInfo[i].FieldName == "NSRBM")
                {
                    e.ColumnsInfo[i].ColumnWidth = 100;
                }
                if (e.ColumnsInfo[i].FieldName == "NSRMC")
                {
                    e.ColumnsInfo[i].ColumnWidth =320;

                }
                if (e.ColumnsInfo[i].FieldName == "FNotes")
                {
                    e.ColumnsInfo[i].ColumnWidth =320 ;
                }
                

            }
          
        }
        void generator_CustomizeColumn(object source, ControlCustomizationEventArgs e)
        {
            if (e.FieldName == "FNotes")
            {
                //XRShape control = new XRShape();
                //control.SizeF = e.Owner.SizeF;
                //control.LocationF = new System.Drawing.PointF(0, 0);
                //e.Owner.Controls.Add(control);
                //control.Shape = new ShapeStar()
                //{
                //    StarPointCount = 5,
                //    Concavity = 30
                //};
                //control.BeforePrint += new System.Drawing.Printing.PrintEventHandler(control_BeforePrint);
                XRTableCell c = e.Owner as XRTableCell;
                c.TextAlignment = TextAlignment.MiddleLeft;
                c.Multiline = true;
                //  e.IsModified = true;
            }
        }
        #region 导出EXCEL
        public ActionResult ExportToXls()
        {
            //var NSRMC = Request["NSRMC"];
            //var FFinance = IsNull(ComboBoxExtension.GetValue<string>("FFinance1"), Request["FFinance"]);
            //var NSRBM = Request["NSRBM"];
            //var NSRSBH = Request["NSRSBH"];
            //var FNewEnterprise = IsNull(ComboBoxExtension.GetValue<string>("FNewEnterprise1"), Request["FNewEnterprise"]);
            //var FIssueID = Request["FIssueID"];
            //var ISPAY = Request["ISPAY"];
            //var FYear = Request["FYear"];
            //var BTJEA = Request["BTJEA"];
            //var BTJEB = Request["BTJEB"];
            //var FApplyDate = Request["FApplyDate"];
            //var LastPayDate = Request["LastPayDate"];
            //var ISBASE = Request["ISBASE"];
            //var FFileNo = Request["FFileNo"];
            //var SKSJA = Request["SKSJA"];
            //var SKSJB = Request["SKSJB"];
            var NSRMC = Fetch.Post("hNSRMC");
            var FFinance = Fetch.Post("hFFinance");
            var NSRBM = Fetch.Post("hNSRBM");
            var NSRSBH = Fetch.Post("hNSRSBH");
            //var FNewEnterprise = Fetch.Post("hFNewEnterprise");
            var FIssueID = Fetch.Post("hFIssueID");
            //var ISPAY = Fetch.Post("hISPAY");
            var FYear = Fetch.Post("hFYear");
            //var BTJEA = Fetch.Post("hBTJEA");
            //var BTJEB = Fetch.Post("hBTJEB");
            //var FApplyDate = Fetch.Post("hFApplyDate");
            //var LastPayDate = Fetch.Post("hLastPayDate");
            //var ISBASE = Fetch.Post("hISBASE");
            //var FFileNo = Fetch.Post("hFFileNo");
            //var SKSJA = Fetch.Post("hSKSJA");
            //var SKSJB = Fetch.Post("hSKSJB");
            //ViewBag.NSRMC = NSRMC;
            //ViewBag.FFinance = FFinance;
            //ViewBag.NSRBM = NSRBM;
            //ViewBag.NSRSBH = NSRSBH;
            //ViewBag.FNewEnterprise = FNewEnterprise;
            //ViewBag.FIssueID = FIssueID;
            //ViewBag.ISPAY = ISPAY;
            //ViewBag.FYear = FYear;
            //ViewBag.BTJEA = BTJEA;
            //ViewBag.BTJEB = BTJEB;
            //ViewBag.FApplyDate = FApplyDate;
            //ViewBag.LastPayDate = LastPayDate;
            //ViewBag.ISBASE = ISBASE;
            //ViewBag.FFileNo = FFileNo;
            //ViewBag.SKSJA = SKSJA;
            //ViewBag.SKSJB = SKSJB;
            //ViewBag.FAmount1 = FAmount1;
            //ViewBag.FAmount2 = FAmount2;
            //ViewBag.FFileNo = FFileNo;
            //    //   ViewBag.FNote = FNote;
            //    //   ViewBag.FPayDateBegin = FPayDateBegin;
            //    //   ViewBag.FPayDateEnd = FPayDateEnd;
            //     //  ViewBag.nsrbm = nsrbm;
            //       ViewBag.nsrmc = nsrmc;
            //       ViewBag.nKHYH = nKHYH;
            //       ViewBag.FFinance = FFinance;
           // var filter = "1=1";
            //if (!string.IsNullOrEmpty(ISPAY) && ISPAY == "true")
            //    filter += string.Format("and NeedAmount =0 ");

            //if (!string.IsNullOrEmpty(ISBASE) && ISBASE == "true")
            //    filter += string.Format("and FBaseAmount >0 ");
            ////if (!string.IsNullOrEmpty(SFBF) && SFBF == "false")
            ////    filter += string.Format("and FAuditAmount > FAmount ");
            ////if (!string.IsNullOrEmpty(nsrbm))
            ////    filter += string.Format("and NSRBM like '%{0}%'", nsrbm);
            //if (!string.IsNullOrEmpty(NSRMC))
            //    filter += string.Format("and NSRMC like '%{0}%' ", NSRMC);
            //if (!string.IsNullOrEmpty(NSRBM))
            //    filter += string.Format("and NSRBM like '%{0}%' ", NSRBM);
            //if (!string.IsNullOrEmpty(NSRSBH))
            //    filter += string.Format("and NSRSBH like '%{0}%' ", NSRSBH);
            //if (!string.IsNullOrEmpty(FIssueID))
            //    filter += string.Format("and FIssueID like '%{0}%' ", FIssueID);
            //if (!string.IsNullOrEmpty(FYear))
            //    filter += string.Format("and FYear = '{0}' ", FYear);
            //if (!string.IsNullOrEmpty(FFinance))
            //    filter += string.Format("and FFinancePropNo = '{0}' ", FFinance);
            //if (!string.IsNullOrEmpty(FNewEnterprise))
            //    filter += string.Format("and FNewEnterprisePropNo= '{0}' ", FNewEnterprise);

            //if (!string.IsNullOrEmpty(FFileNo))
            //{
            //    filter += string.Format("and FFileNo like '%{0}%'", FFileNo);
            //}
            //if (!string.IsNullOrEmpty(BTJEA) & !string.IsNullOrEmpty(BTJEB))
            //{
            //    filter += string.Format(" and FAuditAmount > '{0}'and FAuditAmount < '{1}' ", BTJEA, BTJEB);
            //}
            //if (!string.IsNullOrEmpty(SKSJA) & !string.IsNullOrEmpty(SKSJB))
            //{
            //    filter += string.Format(" and se > '{0}'and se < '{1}' ", SKSJA, SKSJB);
            //}
            //if (!string.IsNullOrEmpty(BTJEA))
            //{
            //    filter += string.Format(" and FAuditAmount > '{0}'", BTJEA);
            //}
            //if (!string.IsNullOrEmpty(BTJEB))
            //{
            //    filter += string.Format(" and FAuditAmount < '{0}' ", BTJEB);
            //}

            //if (!string.IsNullOrEmpty(SKSJA))
            //{
            //    filter += string.Format(" and se > '{0}'", SKSJA);
            //}
            //if (!string.IsNullOrEmpty(SKSJB))
            //{
            //    filter += string.Format(" and se < '{0}'", SKSJB);
            //}

            ////if (!string.IsNullOrEmpty(FAmount))
            ////{
            ////    filter += string.Format(" and FAmount = '{0}' ", FAmount);
            ////}
            ////if (FAmount1 != "" && FAmount2 != "")
            ////{
            ////    filter += " and FAmount >=" + FAmount1 + " and FAmount<=" + FAmount2 + " ";
            ////}
            ////else if (FAmount1 != "")
            ////{
            ////    filter += " and FAmount >=" + FAmount1;
            ////}
            ////else if (FAmount2 != "")
            ////{
            ////    filter += " and FAmount <=" + FAmount2;
            ////}
            ////if (!string.IsNullOrEmpty(FFileNo))
            ////{
            ////    filter += string.Format(" and FFileNo = '{0}' ", FFileNo);
            ////}

            //if (!string.IsNullOrEmpty(FApplyDate) || !string.IsNullOrEmpty(LastPayDate))
            //{
            //    var begin = string.IsNullOrEmpty(FApplyDate) ? DateTime.MinValue.ToString() : FApplyDate;
            //    var end = string.IsNullOrEmpty(LastPayDate) ? DateTime.MaxValue.ToString() : LastPayDate;
            //    filter += string.Format(" AND LastPayDate <= '{0}'", end);
            //    if (!string.IsNullOrEmpty(FApplyDate))
            //        filter += string.Format(" and LastPayDate >= '{0}'", begin);
           // }
            var filter = getfilter(NSRMC, FFinance, NSRBM, NSRSBH, FYear, FIssueID);
            EnterpriseFund.BLL.QueryYearSummarySheet qbll = new BLL.QueryYearSummarySheet();
            var zsxx = qbll.GetModelList(filter);
            var vsbzsxx2 = modeltotable(zsxx);
            //var vsbzsxx2 = from p in zsxx
            //               group p by new { p.NSRDZDAH, p.NSRBM, p.NSRMC, p.NSRSBH, p.FYear } into g
            //               select new
            //               {
            //                   NSRDZDAH = g.Key.NSRDZDAH,

            //                   NSRBM = g.Key.NSRBM,
            //                   NSRMC = g.Key.NSRMC,
            //                   NSRSBH = g.Key.NSRSBH,
            //                   FNotes = string.Join(",", g.Select(h => h.FNote)),
            //                   //  FApplyDate = g.Min(sg => DateTime.Parse(sg.FApplyDate.ToString())).ToString("yyyy-MM-dd"),
            //                   FYear = g.Key.FYear.ToString()
            //               };
            //EnterpriseFund.BLL.QueryAllowance QueryAllowanceInfobll = new EnterpriseFund.BLL.QueryAllowance();
            //var vsbzsxx = QueryAllowanceInfobll.GetModelList(filter);
            //var table = from p in vsbzsxx
            //            group p by new { p.NSRDZDAH, p.NSRBM, p.NSRMC, p.NSRSBH, p.FYear } into g
            //            select new
            //            {
            //                NSRDZDAH = g.Key.NSRDZDAH,

            //                NSRBM = g.Key.NSRBM,
            //                NSRMC = g.Key.NSRMC,
            //                NSRSBH = g.Key.NSRSBH,
            //                FAuditAmount = g.Sum(gs => gs.FAuditAmount) / 10000,
            //                FApplyDate = g.Min(sg => DateTime.Parse(sg.FApplyDate.ToString())).ToString("yyyy-MM-dd"),
            //                FYear = g.Key.FYear.ToString()
            //            };

            // return filter;
            return GridViewExtension.ExportToXls(ExportGridViewSettings, vsbzsxx2, HttpUtility.UrlEncode("年度扶持资金说明表导出.xls"), true);
        }

        static GridViewSettings exportGridViewSettings;
        public static GridViewSettings ExportGridViewSettings
        {

            get
            {

                if (exportGridViewSettings == null)

                    exportGridViewSettings = CreateExportGridViewSettings();
                return exportGridViewSettings;
            }
        }
        private string IsNull(string s1, string s2)
        {
            return string.IsNullOrEmpty(s1) ? s2 : s1;
        }
        //public string ClearViewBag()
        //{
        //    try
        //    {
        //        ViewBag=null;
        //        return "OK";
        //    }
        //    catch (System.Exception ex)
        //    {
        //        return "error";
        //    }
        //}
        public string GetWhereString()
        {
            //绑定值

            //var FTaxClassAllowanceName = IsNull(ComboBoxExtension.GetValue<string>("FTaxClassAllowanceName"), Request["FTaxClassAllowanceName"]);
            //  var nKHYH = Request["NKHYH"];
            var NSRMC = Request["NSRMC"];
            var FFinance = IsNull(ComboBoxExtension.GetValue<string>("FFinance1"), Request["FFinance"]);
            var NSRBM = Request["NSRBM"];
            var NSRSBH = Request["NSRSBH"];
            //var FNewEnterprise = IsNull(ComboBoxExtension.GetValue<string>("FNewEnterprise1"), Request["FNewEnterprise"]);
            var FIssueID = Request["FIssueID"];
            //var ISPAY = Request["ISPAY"];
            var FYear = Request["FYear"];
            //var BTJEA = Request["BTJEA"];
            //var BTJEB = Request["BTJEB"];
            //var FApplyDate = Request["FApplyDate"];
            //var LastPayDate = Request["LastPayDate"];
            //var ISBASE = Request["ISBASE"];
            //var FFileNo = Request["FFileNo"];
            //var SKSJA = Request["SKSJA"];
            //var SKSJB = Request["SKSJB"];
            if (string.IsNullOrEmpty(FYear))
            {
                 FYear = (decimal.Parse(OperateSession.get(Common.GlobalConstant.PARAM_SYSYEAR))).ToString();
            }
           
            //ViewBag.BTJEA = BTJEA;
            //ViewBag.BTJEB = BTJEB;
            //ViewBag.FApplyDate = FApplyDate;
            //ViewBag.LastPayDate = LastPayDate;
            //ViewBag.ISBASE = ISBASE;
            //ViewBag.FFileNo = FFileNo;
            //ViewBag.SKSJA = SKSJA;
            //ViewBag.SKSJB = SKSJB;
            //ViewBag.FAmount1 = FAmount1;
            //ViewBag.FAmount2 = FAmount2;
            //ViewBag.FFileNo = FFileNo;
            //    //   ViewBag.FNote = FNote;
            //    //   ViewBag.FPayDateBegin = FPayDateBegin;
            //    //   ViewBag.FPayDateEnd = FPayDateEnd;
            //     //  ViewBag.nsrbm = nsrbm;
            //       ViewBag.nsrmc = nsrmc;
            //       ViewBag.nKHYH = nKHYH;
            //       ViewBag.FFinance = FFinance;
            var filter = getfilter(NSRMC, FFinance, NSRBM, NSRSBH, FYear, FIssueID);

            return filter;

        }

        private static string getfilter(string NSRMC, string FFinance, string NSRBM, string NSRSBH, string FYear, string FIssueID)
        {
            var filter = "1=1 ";
            //if (!string.IsNullOrEmpty(ISPAY) && ISPAY == "true")
            //    filter += string.Format("and NeedAmount =0 ");

            //if (!string.IsNullOrEmpty(ISBASE) && ISBASE == "true")
            //    filter += string.Format("and FBaseAmount >0 ");
            //if (!string.IsNullOrEmpty(SFBF) && SFBF == "false")
            //    filter += string.Format("and FAuditAmount > FAmount ");
            //if (!string.IsNullOrEmpty(nsrbm))
            //    filter += string.Format("and NSRBM like '%{0}%'", nsrbm);
            if (!string.IsNullOrEmpty(NSRMC))
                filter += string.Format("and NSRMC like '%{0}%' ", NSRMC);
            if (!string.IsNullOrEmpty(NSRBM))
                filter += string.Format("and NSRBM like '%{0}%' ", NSRBM);
            if (!string.IsNullOrEmpty(NSRSBH))
                filter += string.Format("and NSRSBH like '%{0}%' ", NSRSBH);
            if (!string.IsNullOrEmpty(FIssueID))
                filter += string.Format("and FIssueID like '%{0}%' ", FIssueID);
            if (!string.IsNullOrEmpty(FYear))
                filter += string.Format("and FYear = '{0}' ", FYear);
            if (!string.IsNullOrEmpty(FFinance))
                filter += string.Format("and FSpecialAdjustClsNo = '{0}' ", FFinance);
            //if (!string.IsNullOrEmpty(FNewEnterprise))
            //    filter += string.Format("and FNewEnterprisePropNo= '{0}' ", FNewEnterprise);

            //if (!string.IsNullOrEmpty(FFileNo))
            //    filter += string.Format("and FFileNo like '%{0}%'", FFileNo);
            //if (!string.IsNullOrEmpty(BTJEA) & !string.IsNullOrEmpty(BTJEB))
            //{
            //    filter += string.Format(" and FAuditAmount > '{0}'and FAuditAmount < '{1}' ", BTJEA, BTJEB);
            //}
            //if (!string.IsNullOrEmpty(SKSJA) & !string.IsNullOrEmpty(SKSJB))
            //{
            //    filter += string.Format(" and se > '{0}'and se < '{1}' ", SKSJA, SKSJB);
            //}
            //if (!string.IsNullOrEmpty(BTJEA))
            //{
            //    filter += string.Format(" and FAuditAmount > '{0}'", BTJEA);
            //}
            //if (!string.IsNullOrEmpty(BTJEB))
            //{
            //    filter += string.Format(" and FAuditAmount < '{0}' ", BTJEB);
            //}

            //if (!string.IsNullOrEmpty(SKSJA))
            //{
            //    filter += string.Format(" and se > '{0}'", SKSJA);
            //}
            //if (!string.IsNullOrEmpty(SKSJB))
            //{
            //    filter += string.Format(" and se < '{0}'", SKSJB);
            //}
            //if (!string.IsNullOrEmpty(FAmount))
            //{
            //    filter += string.Format(" and FAmount = '{0}' ", FAmount);
            //}
            //if (FAmount1 != "" && FAmount2 != "")
            //{
            //    filter += " and FAmount >=" + FAmount1 + " and FAmount<=" + FAmount2 + " ";
            //}
            //else if (FAmount1 != "")
            //{
            //    filter += " and FAmount >=" + FAmount1;
            //}
            //else if (FAmount2 != "")
            //{
            //    filter += " and FAmount <=" + FAmount2;
            //}
            //if (!string.IsNullOrEmpty(FFileNo))
            //{
            //    filter += string.Format(" and FFileNo = '{0}' ", FFileNo);
            //}

            //if (!string.IsNullOrEmpty(FApplyDate) || !string.IsNullOrEmpty(LastPayDate))
            //{
            //    var begin = string.IsNullOrEmpty(FApplyDate) ? DateTime.MinValue.ToString() : FApplyDate;
            //    var end = string.IsNullOrEmpty(LastPayDate) ? DateTime.MaxValue.ToString() : LastPayDate;
            //    filter += string.Format(" AND LastPayDate <= '{0}'", end);
            //    if (!string.IsNullOrEmpty(FApplyDate))
            //        filter += string.Format(" and LastPayDate >= '{0}'", begin);
            //}
            return filter;
        }
        public List<Model.QueryYearSummarySheet> GetModelVSBZSXX()
        {
            var strWhere = GetWhereString();
            EnterpriseFund.BLL.QueryYearSummarySheet qbll = new BLL.QueryYearSummarySheet();
            var zsxx = qbll.GetModelList(strWhere);
            //EnterpriseFund.BLL.QueryAllowance QueryAllowanceInfobll = new EnterpriseFund.BLL.QueryAllowance();
            //var zsxx = QueryAllowanceInfobll.GetModelList(strWhere);
            return zsxx;
        }
        public static GridViewSettings CreateExportGridViewSettings()
        {
            var setting = new GridViewSettings();
            setting.Name = "gvEditing";
            setting.KeyFieldName = "NSRDZDAH";
            setting.CallbackRouteValues = new { Controller = "QueryYearSummarySheet", Action = "QueryYearSummarySheetListPartial" };
            setting.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            setting.SettingsPager.PageSize = EnterpriseFund.Common.GlobalConstant.CONSTRING_PAGESIZE;
            setting.SettingsExport.Styles.Header.BackColor = System.Drawing.Color.White;
            setting.SettingsExport.Styles.Header.ForeColor = System.Drawing.Color.Black;
            setting.Columns.Add(column =>
            {
                column.Caption = "序号";
                column.FieldName = "rownum";
                column.Width = System.Web.UI.WebControls.Unit.Pixel(30);
                column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
               
            });
            setting.Columns.Add(column =>
            {
                column.Caption = "纳税人编码";
                column.FieldName = "NSRBM";
                column.Width = System.Web.UI.WebControls.Unit.Pixel(60);
                column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
            });
            setting.Columns.Add(column =>
            {
                column.Caption = "企业名称";
                column.FieldName = "NSRMC";
               // column.Width = System.Web.UI.WebControls.Unit.Pixel(150);
                column.CellStyle.HorizontalAlign= System.Web.UI.WebControls.HorizontalAlign.Center;
                
            });
         //   setting.Styles.Row.HorizontalAlign 
         //   setting.Styles.Header.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
           // setting.Columns.Add("rownum", "序号");
           // setting.Columns.Add("NSRBM", "纳税人编码");
           //// setting.Columns.Add("NSRSBH", "纳税人识别号");
           // setting.Columns.Add("NSRMC", "纳税人名称");
         //   setting.Columns.Add("FAuditAmount", "补贴金额(万元)");
         //   setting.Columns.Add("FYear", "补贴年度");
           // setting.Columns.Add("FApplyDate", "补贴日期");
            //setting.Columns.Add("LastPayDate", "补贴日期至");
            //setting.Columns.Add("FAuditAmount", "核定金额");  

            //setting.Columns.Add("FAmount", "已补助金额");
            //setting.Columns.Add("NeedAmount", "还需补助金额");
              // setting.Columns.Add("FNotes", "说明");
            setting.SettingsBehavior.AllowFocusedRow = true;
            setting.SettingsLoadingPanel.Text = "数据读取中...";
            //setting.TotalSummary.Add(DevExpress.Data.SummaryItemType.Count, "NSRBM").DisplayFormat = "总计:";
            //setting.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "FAuditAmount").DisplayFormat = "￥{0}";
            //setting.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "FAuditAmount").DisplayFormat = "合计:￥{0}";
            //setting.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "FAmount").DisplayFormat = "￥{0}";
            //setting.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "FAmount").DisplayFormat = "合计:￥{0}";
            setting.Columns.Add(column =>
            {
               column.Caption = "说明";
                column.FieldName="FNotes";            
                column.ColumnType = MVCxGridViewColumnType.Memo;
                column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
            } );

            setting.SettingsBehavior.EnableCustomizationWindow = true;
			
			
            //setting.TotalSummary.Add(DevExpress.Data.SummaryItemType.Sum, "NeedAmount").DisplayFormat = "￥{0}";
            //setting.GroupSummary.Add(DevExpress.Data.SummaryItemType.Sum, "NeedAmount").DisplayFormat = "合计:￥{0}";
            setting.Settings.ShowGroupPanel = true;
            setting.Settings.ShowFooter = true;
            setting.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";
            setting.ClientSideEvents.EndCallback = "function(){}";

            setting.DataBinding = (sender, e) =>
            {
                ASPxGridView grid = (ASPxGridView)sender;
                for (int i = 0; i < grid.AllColumns.Count; i++)
                {
                    if (grid.AllColumns[i].HeaderStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                    {
                     
                        grid.AllColumns[i].HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
               //  grid.AllColumns[i].CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                     }
                }
            };
            setting.PreRender = setting.BeforeGetCallbackResult = (sender, e) =>
            {


                MVCxGridView gridView = sender as MVCxGridView;
                MVCxGridViewState gridViewState = new MVCxGridViewState(gridView);
                OperateSession.SetToCache(gridViewState, "QueryYearSummarySheet");


            };
            return setting;
        }

        #endregion
    }
}


